var arr = [];//存所有数据
var count = 8;//一页多少条数据
var page = 1;//当前的页数

$.ajax({
    url: 'http://172.17.7.212:3000/admin/getadmin',
    success: function (res) {
        if (res.data.length) {
            arr = res.data;
            rem();
            ret();
        }

    },
})
function rem() {
    $('.motaikuang table tbody').html('');
    $.each(arr.slice((page - 1) * count, page * count), function (i, v) {
        var a = v.type == '1' ? '普通管理员' : "超级管理员";
        $('.motaikuang table tbody').append(
            '<tr>\
    <td class="th1">'+ v.id + '</td>\
    <td>'+ v.name + '</td>\
    <td>'+ v.userId + '</td>\
    <td>'+ a + '</td>\
    <td>\
       
            <button type="button" class="shu" data-toggle="modal" \data-target="#myModal4">\
                删除\
            </button>\
            v
            <div class="modal fade" id="myModal4" tabindex="-1" \role="dialog" aria-labelledby="myModalLabel">\
                <div class="modal-dialog" role="document">\
                    <div class="modal-content">\
                        <div class="modal-header">\
                            <button type="button" class="close" \data-dismiss="modal" aria-label="Close"><span\
                                    aria-hidden="true">&times;</span></button>\
                            <h4 class="modal-title" id="myModalLabel">提示</h4>\
                        </div>\
                        <div class="modal-body">\
                            <span class="iconfont icon-gantanhao"></span>\
                            <span>确定要删除该公告吗？</span>\
                        </div>\
                        <div class="anlu modal-footer">\
                            <button type="button" class="btn btn-default" \data-dismiss="modal">取消</button>\
                            <button type="button" class="btn btn-primary">确定</\button>\
                        </div>\
                    </div>\
                </div>\
            </div>\
            <button type="button" class="shu" data-toggle="modal" \data-target="#exampleModal4"\
                data-whatever="@mdo">修改</button>\
            <div class="modal fade" id="exampleModal4" tabindex="-1" \role="dialog"\
                aria-labelledby="exampleModalLabel">\
                <div class="modal-dialog" role="document">\
                    <div class="modal-content">\
                        <div class="modal-header">\
                            <button type="button" class="close" \data-dismiss="modal" aria-label="Close"><span\
                                    aria-hidden="true">&times;</span></button>\
                            <h4 class="modal-title" id="exampleModalLabel">修改管\理员信息</h4>\
                        </div>\
                        <div class="modal-body">\
                            <form class="form-horizontal">\
                                <div class="form-group">\
                                    <label for="inputPassword"\
                                        class="col-sm-2 control-label"><span>*</\span>编号</label>\
                                    <div class="col-sm-10">\
                                        <input type="text" disabled \class="form-control" id="inputPassword"\
                                            placeholder="6">\
                                    </div>\
                                </div>\
                                <div class="form-group">\
                                    <label for="inputPassword"\
                                        class="col-sm-2 control-label"><span>*</\span>姓名</label>\
                                    <div class="col-sm-10">\
                                        <input type="text" class="form-control"\ id="inputPassword"\
                                            placeholder="公告4">\
                                    </div>\
</div>\
                                <div class="form-group">\
                                    <label for="inputPassword"\
                                        class="col-sm-2 control-label"><span>*</span>\账号</label>\
                                    <div class="col-sm-10">\
                                        <input type="text" disabled \class="form-control" id="inputPassword"\
                                            placeholder="6号管理员">\
                                    </div>\
                                </div>\
                                <div class="form-group">\
                                    <label for="inputPassword"\
                                        class="col-sm-2 control-label"><span>*</span>\密码</label>\
                                    <div class="col-sm-10">\
                                        <input type="text" class="form-control" \id="inputPassword"\
                                            placeholder="***">\
                                    </div>\
                                </div>\
                                <div class="form-group">\
                                    <label for="inputPassword"\
                                        class="col-sm-2 control-label"><span>*</span>\类型</label>\
                                    <div class="col-lg-6">\
                                        <div class="input-group">\
                                            <input type="text" class="form-control"\ aria-label="...">\
                                            <div class="input-group-btn">\
                                                <button type="button" class="btn\ btn-default dropdown-toggle"\
                                                    data-toggle="dropdown"\ aria-haspopup="true"\
                                                    aria-expanded="false">超级管理员\ V</button>\
                                                <ul class="dropdown-menu\ dropdown-menu-right">\
                                                    <li><a href="#">普通管理员</a></\li>\
                                                    <li><a href="#">超级管理员</a></\li>\
                                                </ul>\
                                            </div>\
                                        </div>\
                                    </div>\
                                </div>\
                        </div>\
                        <div class="modal-footer">\
                            <button type="button" class="btn btn-default"\ data-dismiss="modal">取消</button>\
                            <button type="button" class="btn btn-primary ">确定</\button>\
                        </div>\
                        </form>\
                    </div>\
                </div>\
            </div>\
        </div>\
        </div>\
    </td>\
</tr>'
        )
    })
}
$('#nav2').on('click','li', function () {
    page = $(this).text();
    rem();
})
console.log($('.j-add-name').text())  
function ret() {
    var n = Math.ceil(arr.length / count);
    for (var i = 1; i <= n; i++) {
        $('.yeshu').before($('<li><a href="#">' + i + '</a></li>'));
    }
}
$('.j-add-btn').on('click', function(){
    // console.log(11);
    $.ajax({
      url:'http://172.17.7.212:3000/admin/addadmin',
      data:{
        name:$('.j-add-name').val(),
        password:$('.j-add-password').val(),
        type:$('.j-add-type').val(),
        userId:$('.j-add-user').val(),
      },

      type:'post',
      success:function(res){
        console.log(res)
        if(res.code==200){
            $('#exampleModal1').modal('hide');
            rem();
        }else{
            alert('添加失败')
        }
      }
    })
  })